<?php
namespace Home\Controller;
use Think\Controller;
header("Content-type:text/html;charset=utf-8");
class AchievementController extends BaseController {
	//年份查
	public function score_list(){
		if(IS_POST){
			$id = $_POST['id']; // 考核记录表id
			$worker_id = session('worker_id');
			// var_dump($worker_id);die;
			$worker =  M('worker')->where('worker_id='.$worker_id)->find();
			$posts_id = $worker['posts_id'];
			$posts = M('posts')->where('posts_id='.$posts_id)->find();
			$parent_id = $posts['parent_id'];

			$notes = M('notes')->where('id='.$id)->find();
			$time = $notes['ktime'];
			$map['test_time'] = $time;
			$map['worker_id'] = $worker_id;
			$list = M('score')->where($map)->select();
			// echo "<pre>";
			// var_dump($list);
			// echo "</pre>";die;
			// 获取该人员在自己岗位下的分档信息
			$map1['posts'] = $parent_id;
			$map1['ktime'] = date("Y",$notes['ktime']);
			$class = M('class')->where($map1)->select();
			// var_dump($class);die;
			foreach($list as $key => $val){
				if($val['sum'] >= $class['0']['bottom'] && $val['sum'] < $class['0']['top']){
					$list[$key]['dang'] = '优秀';
				}elseif($val['sum'] >= $class['1']['bottom'] && $val['sum'] < $class['1']['top']){
					$list[$key]['dang'] = '良好';
				}elseif($val['sum'] >= $class['2']['bottom'] && $val['sum'] < $class['2']['top']){
					$list[$key]['dang'] = '一般';
				}elseif($val['sum'] >= $class['3']['bottom'] && $val['sum'] < $class['3']['top']){
					$list[$key]['dang'] = '差';
				}
			}
			// echo "<pre>";
			// var_dump($list);
			// echo "</pre>";die;
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$list);
			$this->display('score_list3');
		}else{
			$notes = M('notes')->order('ktime desc')->select();
			// var_dump($notes);die;			
			$worker_id = session('worker_id'); 
			$worker =  M('worker')->where('worker_id='.$worker_id)->find();
			$posts_id = $worker['posts_id'];
			$posts = M('posts')->where('posts_id='.$posts_id)->find();
			$parent_id = $posts['parent_id'];
			// var_dump($parent_id);die;
			$map['worker_id'] = $worker_id;
			$map['test_time'] = $notes['0']['ktime'];
			$list = M('score')->where($map)->select();
			// echo "<pre>";
			// var_dump($list);
			// echo "</pre>";die;
			// 获取该人员在自己岗位下的分档信息
			$map1['posts'] = $parent_id;
			$map1['ktime'] = date("Y",$notes['0']['ktime']);
			$class = M('class')->where($map1)->select();
			// var_dump($class);die;
			foreach($list as $key => $val){
				if($val['sum'] >= $class['0']['bottom'] && $val['sum'] < $class['0']['top']){
					$list[$key]['dang'] = '优秀';
				}elseif($val['sum'] >= $class['1']['bottom'] && $val['sum'] < $class['1']['top']){
					$list[$key]['dang'] = '良好';
				}elseif($val['sum'] >= $class['2']['bottom'] && $val['sum'] < $class['2']['top']){
					$list[$key]['dang'] = '一般';
				}elseif($val['sum'] >= $class['3']['bottom'] && $val['sum'] < $class['3']['top']){
					$list[$key]['dang'] = '差';
				}
			}
			// echo "<pre>";
			// var_dump($list);
			// echo "</pre>";die;
			if(empty($list)){
				$status = 0;
				echo json_encode($status);
			}else{
				$this->assign('score',$list);
				$this->assign('notes',$notes);
				$this->assign('worker_id',$worker_id);
				$this->display();
			}
		}				
			
	}

	//月份查
	public function score_list1(){
		// var_dump($_POST);die;
		$id = $_POST['id']; // 考核表id
		$month = $_POST['month']; // 月份
		$worker_id = session('worker_id'); // 职员id
		// var_dump($worker_id);die;
		$worker =  M('worker')->where('worker_id='.$worker_id)->find();
		$posts_id1 = $worker['posts_id'];
		$posts = M('posts')->where('posts_id='.$posts_id1)->find();
		$posts_id = $posts['parent_id'];

		$notes = M('notes')->where('id='.$id)->find();
		$year = date("Y",$notes['ktime']);
		
		$mp1['worker_id'] = $worker_id;
		$mp1['test_time'] = $notes['ktime'];
		$sc = M('score')->where($mp1)->select();
		foreach($sc as $k2 => $v2){
			$score_id[] = $v2['id'];
		}
		if($month == '1'){
			$ctime1 = strtotime($year .'-'. $month); // 要查看的年-月
			$ctime2 = $year . '-0' . $month;
			$map1['mtime'] = $ctime1;
			$map1['score_id'] = array('in',$score_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = $ctime2;
			$map2['score_id'] = array('in',$score_id);
			$map2['ktime'] = $notes['ktime'];
		}else{
			for($i = 1;$i <= $month;$i++){
				$a[] = $i;
			}
			foreach($a as $k => $v){
				$ctime1[] = strtotime($year .'-'. $v);
				if($v == 10){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
				}elseif($v == 11){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
					$ctime2['10'] = $year . '-' . '11';
				}elseif($v == 12){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
					$ctime2['10'] = $year . '-' . '11';
					$ctime2['11'] = $year . '-' . '12';
				}else{
					$ctime2[] = $year . '-0' . $v;
				}
			}
			// var_dump($ctime1);die;
			$map1['mtime'] = array('in',$ctime1);
			$map1['score_id'] = array('in',$score_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = array('in',$ctime2);
			$map2['score_id'] = array('in',$score_id);
			$map2['ktime'] = $notes['ktime'];
		}
		$detail = M('detail')->where($map1)->select();
		// var_dump($detail);
		$entry = M('entry')->where($map2)->select();
		// var_dump($entry);die;
		if(empty($detail) && empty($entry)){
			// 默认值
			foreach($sc as $key => $val){
				$sc[$key]['public'] = 10;
				$sc[$key]['part'] = 10;
				$sc[$key]['price'] = 0;
				$sc[$key]['check'] = 0;
				$sc[$key]['work'] = 70;
				$sc[$key]['sum'] = 90;
			}
			$map1['posts'] = $posts_id;
			$map1['ktime'] = $year;
			$class = M('class')->where($map1)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// echo "<pre>";
			// var_dump($list);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('month',$month);
			$this->assign('year',$year);
			$this->display();
		}elseif(empty($detail)){
			// 计算entry表中的数据
			foreach($sc as $k => $v){
				$sc[$k]['public'] = 10;
				$sc[$k]['part'] = 10;
				$sc[$k]['price'] = 0;
				$sc[$k]['check'] = 0;
				$map4['mtime'] = array('in',$ctime2);
				$map4['score_id'] = $v['id'];
				$map4['ktime'] = $notes['ktime'];
				$entry1 = M('entry')->where($map4)->select();
				if(empty($entry1)){
					$sc[$k]['work'] = 70;
				}else{
					foreach($entry1 as $Key8 => $val8){
						$entry2[] = $val8['score'];
					}
					$work2 = array_sum($entry2);
					$sc[$k]['work'] = 70 + $work2;
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('month',$month);
			$this->assign('year',$year);
			$this->display();
		}elseif(empty($entry)){
			// 计算detail表中的数据
			foreach($detail as $key => $val){
				$p_id1[] = $val['p_id'];
			}
			$p_id = array_unique($p_id1);
			foreach($sc as $k => $v){
				foreach($p_id as $key1 => $val1){
					if($val1 == '7'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '7';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key3 => $val3){
								$pub[] = $val3['score'];
							}
							$public = array_sum($pub);
							$sc[$k]['public'] = 10 + $public;
						}else{
							$sc[$k]['public'] = 10;
						}
					}elseif($val1 == '8'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '8';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key4 => $val4){
								$par[] = $val4['score'];
							}
							$part = array_sum($par);
							$sc[$k]['part'] = 10 + $part;
						}else{
							$sc[$k]['part'] = 10;
						}
					}elseif($val1 == '9'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '9';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key5 => $val5){
								$pric[] = $val5['score'];
							}
							$price = array_sum($pric);
							$sc[$k]['price'] = 0 + $price;
						}else{
							$sc[$k]['price'] = 0;
						}
					}elseif($val1 == '10'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '10';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key6 => $val6){
								$cscore[] = $val6['score'];
							}
							$zscore = array_sum($cscore);
							$sc[$k]['check'] = 0 + $zscore;
						}else{
							$sc[$k]['check'] = 0;
						}
					}elseif($val1 == '11'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '11';
						$map3['ktime'] = $notes['ktime'];
						$detail1 = M('detail')->where($map3)->select();
						if(empty($detail1)){
							$sc[$k]['work'] = 70;
						}else{
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							$sc[$k]['work'] = 70 + $work1;
						}
					}
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('month',$month);
			$this->assign('year',$year);
			$this->display();
		}else{
			// var_dump('haha');die;
			// 计算detail表和entry表中的数据和
			foreach($detail as $key => $val){
				$p_id1[] = $val['p_id'];
			}
			$p_id = array_unique($p_id1);
			foreach($sc as $k => $v){
				foreach($p_id as $key1 => $val1){
					if($val1 == '7'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '7';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key3 => $val3){
								$pub[] = $val3['score'];
							}
							$public = array_sum($pub);
							$sc[$k]['public'] = 10 + $public;
						}else{
							$sc[$k]['public'] = 10;
						}
					}elseif($val1 == '8'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '8';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key4 => $val4){
								$par[] = $val4['score'];
							}
							$part = array_sum($par);
							$sc[$k]['part'] = 10 + $part;
						}else{
							$sc[$k]['part'] = 10;
						}
					}elseif($val1 == '9'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '9';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key5 => $val5){
								$pric[] = $val5['score'];
							}
							$price = array_sum($pric);
							$sc[$k]['price'] = 0 + $price;
						}else{
							$sc[$k]['price'] = 0;
						}
					}elseif($val1 == '10'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '10';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key6 => $val6){
								$cscore[] = $val6['score'];
							}
							$zscore = array_sum($cscore);
							$sc[$k]['check'] = 0 + $zscore;
						}else{
							$sc[$k]['check'] = 0;
						}
					}elseif($val1 == '11'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '11';
						$map3['ktime'] = $notes['ktime'];
						$map4['mtime'] = array('in',$ctime2);
						$map4['score_id'] = $v['id'];
						$map4['ktime'] = $notes['ktime'];
						$detail1 = M('detail')->where($map3)->select();
						$entry1 = M('entry')->where($map4)->select();
						if(empty($detail1) && empty($entry1)){
							$sc[$k]['work'] = 70;
						}elseif(empty($detail1)){
							foreach($entry1 as $Key8 => $val8){
								$entry2[] = $val8['score'];
							}
							$work2 = array_sum($entry2);
							$sc[$k]['work'] = 70 + $work2;
						}elseif(empty($entry1)){
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							$sc[$k]['work'] = 70 + $work1;
						}else{
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							foreach($entry1 as $Key8 => $val8){
								$entry2[] = $val8['score'];
							}
							$work2 = array_sum($entry2);
							$sc[$k]['work'] = 70 + $work1 + $work2;
						}
					}
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('month',$month);
			$this->assign('year',$year);
			$this->display();
		}
	}

	//季度查
	public function score_list2(){
		// var_dump($_POST);die;
		$id = $_POST['id']; // 考核表id
		// var_dump($id);die;
		$quarter = $_POST['quarter']; // 季度
		$worker_id = session('worker_id'); // 岗位id
		// var_dump($worker_id);die;
		$worker =  M('worker')->where('worker_id='.$worker_id)->find();
		$posts_id1 = $worker['posts_id'];
		$posts = M('posts')->where('posts_id='.$posts_id1)->find();
		$posts_id = $posts['parent_id'];

		$notes = M('notes')->where('id='.$id)->find();
		$year = date("Y",$notes['ktime']);
		$mp1['worker_id'] = $worker_id;
		$mp1['test_time'] = $notes['ktime'];
		$sc = M('score')->where($mp1)->select();
		foreach($sc as $k2 => $v2){
			$sc_id[] = $v2['id'];
		}
		if($quarter == '1'){
			for($i = 1;$i <= 3;$i++){
				$a[] = $i;
			}
			foreach($a as $k => $v){
				$ctime1[] = strtotime($year .'-0'. $v);
				$ctime2[] = $year . '-0' . $v;
			}
			$map1['mtime'] = array('in',$ctime1);
			$map1['score_id'] = array('in',$sc_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = array('in',$ctime2);
			$map2['score_id'] = array('in',$sc_id);
			$map2['ktime'] = $notes['ktime'];
		}elseif($quarter == '2'){
			for($i = 1;$i <= 6;$i++){
				$a[] = $i;
			}
			foreach($a as $k => $v){
				$ctime1[] = strtotime($year . '-0' . $v);
				$ctime2[] = $year . '-0' . $v;
			}
			$map1['mtime'] = array('in',$ctime1);
			$map1['score_id'] = array('in',$sc_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = array('in',$ctime2);
			$map2['score_id'] = array('in',$sc_id);
			$map2['ktime'] = $notes['ktime'];
		}elseif($quarter == '3'){
			for($i = 1;$i <= 9;$i++){
				$a[] = $i;
			}
			foreach($a as $k => $v){
				$ctime1[] = strtotime($year . '-0' . $v);
				$ctime2[] = $year . '-0' . $v;
			}
			$map1['mtime'] = array('in',$ctime1);
			$map1['score_id'] = array('in',$sc_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = array('in',$ctime2);
			$map2['score_id'] = array('in',$sc_id);
			$map2['ktime'] = $notes['ktime'];
		}elseif($quarter == '4'){
			for($i = 1;$i <= 12;$i++){
				$a[] = $i;
			}
			foreach($a as $k => $v){
				$ctime1[] = strtotime($year . '-' . $v);
				if($v == 10){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
				}elseif($v == 11){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
					$ctime2['10'] = $year . '-' . '11';
				}elseif($v == 12){
					$ctime2[] = $year . '-0' . $v;
					$ctime2['9'] = $year . '-' . '10';
					$ctime2['10'] = $year . '-' . '11';
					$ctime2['11'] = $year . '-' . '12';
				}else{
					$ctime2[] = $year . '-0' . $v;
				}
			}
			$map1['mtime'] = array('in',$ctime1);
			$map1['score_id'] = array('in',$sc_id);
			$map1['ktime'] = $notes['ktime'];
			$map2['mtime'] = array('in',$ctime2);
			$map2['score_id'] = array('in',$sc_id);
			$map2['ktime'] = $notes['ktime'];
		}
		$detail = M('detail')->where($map1)->select();
		$entry = M('entry')->where($map2)->select();
		if(empty($detail) && empty($entry)){
			// 默认值
			foreach($sc as $key => $val){
				$sc[$key]['public'] = 10;
				$sc[$key]['part'] = 10;
				$sc[$key]['price'] = 0;
				$sc[$key]['check'] = 0;
				$sc[$key]['work'] = 70;
				$sc[$key]['sum'] = 90;
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// 排序
			$sums = array();
			foreach($sc as $li){
				$sums[] = $li['sum'];
			}
			array_multisort($sums,SORT_DESC,$sc);
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('quarter',$quarter);
			$this->assign('year',$year);
			$this->display();
		}elseif(empty($detail)){
			// 计算entry表中的数据
			foreach($sc as $k => $v){
				$sc[$k]['public'] = 10;
				$sc[$k]['part'] = 10;
				$sc[$k]['price'] = 0;
				$sc[$k]['check'] = 0;
				$map4['mtime'] = array('in',$ctime2);
				$map4['score_id'] = $v['id'];
				$map4['ktime'] = $notes['ktime'];
				$entry1 = M('entry')->where($map4)->select();
				if(empty($entry1)){
					$sc[$k]['work'] = 70;
				}else{
					foreach($entry1 as $Key8 => $val8){
						$entry2[] = $val8['score'];
					}
					$work2 = array_sum($entry2);
					$sc[$k]['work'] = 70 + $work2;
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// 排序
			$sums = array();
			foreach($sc as $li){
				$sums[] = $li['sum'];
			}
			array_multisort($sums,SORT_DESC,$sc);
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('quarter',$quarter);
			$this->assign('year',$year);
			$this->display();
		}elseif(empty($entry)){
			// 计算detail表中的数据
			foreach($detail as $key => $val){
				$p_id1[] = $val['p_id'];
			}
			$p_id = array_unique($p_id1);
			foreach($sc as $k => $v){
				foreach($p_id as $key1 => $val1){
					if($val1 == '7'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '7';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key3 => $val3){
								$pub[] = $val3['score'];
							}
							$public = array_sum($pub);
							$sc[$k]['public'] = 10 + $public;
						}else{
							$sc[$k]['public'] = 10;
						}
					}elseif($val1 == '8'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '8';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key4 => $val4){
								$par[] = $val4['score'];
							}
							$part = array_sum($par);
							$sc[$k]['part'] = 10 + $part;
						}else{
							$sc[$k]['part'] = 10;
						}
					}elseif($val1 == '9'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '9';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key5 => $val5){
								$pric[] = $val5['score'];
							}
							$price = array_sum($pric);
							$sc[$k]['price'] = 0 + $price;
						}else{
							$sc[$k]['price'] = 0;
						}
					}elseif($val1 == '10'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '10';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key6 => $val6){
								$cscore[] = $val6['score'];
							}
							$zscore = array_sum($cscore);
							$sc[$k]['check'] = 0 + $zscore;
						}else{
							$sc[$k]['check'] = 0;
						}
					}elseif($val1 == '11'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '11';
						$map3['ktime'] = $notes['ktime'];
						$detail1 = M('detail')->where($map3)->select();
						if(empty($detail1)){
							$sc[$k]['work'] = 70;
						}else{
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							$sc[$k]['work'] = 70 + $work1;
						}
					}
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// 排序
			$sums = array();
			foreach($sc as $li){
				$sums[] = $li['sum'];
			}
			array_multisort($sums,SORT_DESC,$sc);
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$worker_id);
			$this->assign('score',$sc);
			$this->assign('quarter',$quarter);
			$this->assign('year',$year);
			$this->display();
		}else{
			// 计算detail表和entry表中的数据和
			foreach($detail as $key => $val){
				$p_id1[] = $val['p_id'];
			}
			$p_id = array_unique($p_id1);
			foreach($sc as $k => $v){
				foreach($p_id as $key1 => $val1){
					if($val1 == '7'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '7';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key3 => $val3){
								$pub[] = $val3['score'];
							}
							$public = array_sum($pub);
							$sc[$k]['public'] = 10 + $public;
						}else{
							$sc[$k]['public'] = 10;
						}
					}elseif($val1 == '8'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '8';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key4 => $val4){
								$par[] = $val4['score'];
							}
							$part = array_sum($par);
							$sc[$k]['part'] = 10 + $part;
						}else{
							$sc[$k]['part'] = 10;
						}
					}elseif($val1 == '9'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '9';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key5 => $val5){
								$pric[] = $val5['score'];
							}
							$price = array_sum($pric);
							$sc[$k]['price'] = 0 + $price;
						}else{
							$sc[$k]['price'] = 0;
						}
					}elseif($val1 == '10'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '10';
						$map3['ktime'] = $notes['ktime'];
						$zhi = M('detail')->where($map3)->select();
						if(!empty($zhi)){
							foreach($zhi as $key6 => $val6){
								$cscore[] = $val6['score'];
							}
							$zscore = array_sum($cscore);
							$sc[$k]['check'] = 0 + $zscore;
						}else{
							$sc[$k]['check'] = 0;
						}
					}elseif($val1 == '11'){
						$map3['mtime'] = array('in',$ctime1);
						$map3['score_id'] = $v['id'];
						$map3['p_id'] = '11';
						$map3['ktime'] = $notes['ktime'];
						$map4['mtime'] = array('in',$ctime2);
						$map4['score_id'] = $v['id'];
						$map4['ktime'] = $notes['ktime'];
						$detail1 = M('detail')->where($map3)->select();
						$entry1 = M('entry')->where($map4)->select();
						if(empty($detail1) && empty($entry1)){
							$sc[$k]['work'] = 70;
						}elseif(empty($detail1)){
							foreach($entry1 as $Key8 => $val8){
								$entry2[] = $val8['score'];
							}
							$work2 = array_sum($entry2);
							$sc[$k]['work'] = 70 + $work2;
						}elseif(empty($entry1)){
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							$sc[$k]['work'] = 70 + $work1;
						}else{
							foreach($detail1 as $key7 => $val7){
								$detail2[] = $val7['score'];
							}
							$work1 = array_sum($detail2);
							foreach($entry1 as $Key8 => $val8){
								$entry2[] = $val8['score'];
							}
							$work2 = array_sum($entry2);
							$sc[$k]['work'] = 70 + $work1 + $work2;
						}
					}
				}
				$sc[$k]['sum'] = $sc[$k]['public'] + $sc[$k]['part'] + $sc[$k]['price'] + $sc[$k]['check'] + $sc[$k]['work'];
			}
			$map5['posts'] = $posts_id;
			$map5['ktime'] = $year;
			$class = M('class')->where($map5)->select();
			foreach($sc as $key9 => $val9){
				if($val9['sum'] >= $class['0']['bottom'] && $val9['sum'] < $class['0']['top']){
					$sc[$key9]['dang'] = '优秀';
				}elseif($val9['sum'] >= $class['1']['bottom'] && $val9['sum'] < $class['1']['top']){
					$sc[$key9]['dang'] = '良好';
				}elseif($val9['sum'] >= $class['2']['bottom'] && $val9['sum'] < $class['2']['top']){
					$sc[$key9]['dang'] = '一般';
				}elseif($val9['sum'] >= $class['3']['bottom'] && $val9['sum'] < $class['3']['top']){
					$sc[$key9]['dang'] = '差';
				}
			}
			// 排序
			$sums = array();
			foreach($sc as $li){
				$sums[] = $li['sum'];
			}
			array_multisort($sums,SORT_DESC,$sc);
			// echo "<pre>";
			// var_dump($sc);
			// echo "</pre>";die;
			$this->assign('notes_id',$id);
			$this->assign('worker_id',$posts_id);
			$this->assign('score',$sc);
			$this->assign('quarter',$quarter);
			$this->assign('year',$year);
			$this->display();
		}
	}	
} 